var baseurl = "http://222.25.188.1:48888";
let projectTotal;
$(function() {
	$('.main-form-button').click(function() {
	    	var name = $("#email").val();
	     	var pass = $("#password").val();		
	    if (name.length == 0 || pass.length == 0) {
	        	$('#popBox1').trigger('click');
	    } else {
	        var data1 = {
	            "email": name,
	            "password": pass
	        };
	        postHttp({
	            url: "/user/login",
	            data: JSON.stringify(data1),
	            type: 'post',
	            dataType: 'json',
	            contentType: 'application/json',
	        }).then((res) => {
						console.log(res)
							let token = res.token
	            window.localStorage.setItem("saveToken",token);
							// var myWebSocket = new WebSocket("ws://222.25.188.1:48888/websocket"); //建立连接
							// myWebSocket.onopen = function() { //发送请求
							// 	console.log("open");
							// 	//myWebSocket.send("Hello WebSocket");
							// };
							// myWebSocket.onmessage = function(e) { //获取后端响应
							// 	console.log(e.data);
							// 	let realtimePeople = e.data.split(':')[1]
							// 	window.localStorage.setItem("saveRealtimePeople",realtimePeople);
							// 	console.log(realtimePeople);
							// };
							// myWebSocket.onclose = function(e) {
							// 	console.log("close");
							// };
							// myWebSocket.onerror = function(e) {
							// 	console.log("error");
							// };
							window.open("../../html/main/productList.html","_self");
	        }).catch(res => {
	            console.log(res);
							var popBox = document.getElementById("popBox");
							var popLayer = document.getElementById("popLayer");
							popBox.style.display = "block";
							popLayer.style.display = "block";
	        })
	    }
			window.localStorage.setItem("username",name);
	})
	// $('.main-form-button').click(function() {
	// 	var name = $("#email").val();
	// 	var pass = $("#password").val();		
	// 	var flag = 0;
	// 	$('#popBox1').trigger('click');
	// 	$.ajax({
	// 		async: false,
	// 		url: "/user/login",
	// 		type: "get",
	// 		dataType: "json",
	// 		/* data: {
	// 			username : $("#email").val(),
	// 			password : $("#password").val()
	// 		}, */
	// 		success: function(data) {
	// 			$.each(data, function(i, item) {
	// 				if (name == item["email"] && pass == item["password"]) {					
	// 					/* window.open("../../html/main/productList.html?username=" +name); */
	// 					window.open("../../html/main/productList.html");
	// 					flag = 1;						
	// 				}
	// 			})
	// 			if (flag == 0) {
	// 				var popBox = document.getElementById("popBox");
	// 				var popLayer = document.getElementById("popLayer");
	// 				popBox.style.display = "block";
	// 				popLayer.style.display = "block";
	// 			}
	// 		},
	// 		error: function(data) {
	// 			console.log(data);
	// 		}
	// 	})
	// 	window.localStorage.setItem("username",name);
	// })
 })
	// /*点击弹出按钮*/
	// document.getElementById("popBox1").onclick = function() {
	//     var popBox = document.getElementById("popBox");
	//     var popLayer = document.getElementById("popLayer");
	//     popBox.style.display = "block";
	//     popLayer.style.display = "block";
	// }   
	/*点击关闭按钮*/
	document.getElementById("closeBox").onclick = function() {
	    var popBox = document.getElementById("popBox");
	    var popLayer = document.getElementById("popLayer");
	    popBox.style.display = "none";
	    popLayer.style.display = "none";
	}
